home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / PowerD / Pdmod / modules / net / if.m < prev    next >
Encoding:
Text File  |  2002-10-28  |  10.5 KB  |  265 lines

  1. /*
  2. **      $Filename: net/if.h $
  3. **      $Release$
  4. **      $Revision: 3.1 $
  5. **      $Date: 1994/02/03 11:56:05 $
  6. **
  7. **      Network interface
  8. **
  9. **      Copyright © 1993,1994 AmiTCP/IP Group, <AmiTCP-Group@hut.fi>
  10. **                  Helsinki University of Technology, Finland.
  11. **                  All rights reserved.
  12. */
  13.  
  14. /*
  15.  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  16.  * All rights reserved.
  17.  *
  18.  * Redistribution and use in source and binary forms, with or without
  19.  * modification, are permitted provided that the following conditions
  20.  * are met:
  21.  * 1. Redistributions of source code must retain the above copyright
  22.  *    notice, this list of conditions and the following disclaimer.
  23.  * 2. Redistributions in binary form must reproduce the above copyright
  24.  *    notice, this list of conditions and the following disclaimer in the
  25.  *    documentation and/or other materials provided with the distribution.
  26.  * 3. All advertising materials mentioning features or use of this software
  27.  *    must display the following acknowledgement:
  28.  *      This product includes software developed by the University of
  29.  *      California, Berkeley and its contributors.
  30.  * 4. Neither the name of the University nor the names of its contributors
  31.  *    may be used to endorse or promote products derived from this software
  32.  *    without specific prior written permission.
  33.  *
  34.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  35.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  36.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  37.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  38.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  39.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  40.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  42.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  43.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  44.  * SUCH DAMAGE.
  45.  *
  46.  *      @(#)if.h        7.11 (Berkeley) 3/19/91
  47.  */
  48.  
  49. /*
  50.  * Structures defining a network interface, providing a packet
  51.  * transport mechanism (ala level 0 of the PUP protocols).
  52.  *
  53.  * Each interface accepts output datagrams of a specified maximum
  54.  * length, and provides higher level routines with input datagrams
  55.  * received from its medium.
  56.  *
  57.  * Output occurs when the routine if_output is called, with three parameters:
  58.  *      (*ifp->if_output)(ifp, m, dst)
  59.  * Here m is the mbuf chain to be sent and dst is the destination address.
  60.  * The output routine encapsulates the supplied datagram if necessary,
  61.  * and then transmits it on its medium.
  62.  *
  63.  * On input, each interface unwraps the data received by it, and either
  64.  * places it on the input queue of a internetwork datagram routine
  65.  * and posts the associated software interrupt, or passes the datagram to a raw
  66.  * packet input routine.
  67.  *
  68.  * Routines exist for locating interfaces by their addresses
  69.  * or for locating a interface on a certain network, as well as more general
  70.  * routing and gateway routines maintaining information used to locate
  71.  * interfaces.  These routines live in the files if.c and route.c
  72.  */
  73.  
  74. //MODULE 'sys/time'
  75.  
  76.  
  77. /*
  78.  * Structure defining a queue for a network interface.
  79.  *
  80.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  81.  */
  82.  
  83. OBJECT ifqueue
  84.     ifq_head:PTR TO mbuf,
  85.     ifq_tail:PTR TO mbuf,
  86.     ifq_len:LONG,
  87.     ifq_maxlen:LONG,
  88.     ifq_drops:LONG
  89.  
  90.  
  91. OBJECT ifnet
  92.     if_name:PTR TO BYTE,               /* name, e.g. ``en'' or ``lo'' */
  93.     if_unit:WORD,                /* sub-unit for lower level driver */
  94.     if_mtu:WORD,                 /* maximum transmission unit */
  95.     if_flags:WORD,               /* up/down, broadcast, etc. */
  96.     if_timer:WORD,               /* time 'til if_watchdog called */
  97.     if_metric:LONG,              /* routing metric (external only) */
  98.     if_addrlist:PTR TO ifaddr,    /* linked list of addresses per if */
  99.     if_snd:PTR TO ifqueue,         /* output queue */
  100. /* procedure handles */
  101.     if_init:LONG,           /* init routine */
  102.     if_output:LONG,    /* output routine (enqueue) */
  103.     if_start:LONG,          /* initiate output routine */
  104.     if_done:LONG,           /* output complete routine */
  105.     if_ioctl:LONG, /* ioctl routine */
  106.     if_reset:LONG,          /* bus reset routine */
  107.     if_watchdog:LONG,       /* timer routine */
  108. /* generic interface statistics */
  109.     if_ipackets:LONG,            /* packets received on interface */
  110.     if_ierrors:LONG,             /* input errors on interface */
  111.     if_opackets:LONG,            /* packets sent on interface */
  112.     if_oerrors:LONG,             /* output errors on interface */
  113.     if_collisions:LONG,          /* collisions on csma interfaces */
  114. /* end statistics */
  115.     if_next:PTR TO ifnet,
  116.     if_type:UBYTE,                /* ethernet, tokenring, etc */
  117.     if_addrlen:UBYTE,             /* media address length */
  118.     if_hdrlen:UBYTE,              /* media header length */
  119.     if_index:UBYTE,               /* numeric abbreviation for this if  */
  120. /* more statistics here to avoid recompiling netstat */
  121.     if_lastchange:TimeVal,  /* last updated */
  122.     if_ibytes:LONG,              /* total number of octets received */
  123.     if_obytes:LONG,              /* total number of octets sent */
  124.     if_imcasts:LONG,             /* packets received via multicast */
  125.     if_omcasts:LONG,             /* packets sent via multicast */
  126.     if_iqdrops:LONG,             /* dropped on input, this interface */
  127.     if_noproto:LONG,             /* destined for unsupported protocol */
  128.     if_baudrate:LONG,            /* linespeed */
  129.     if_pcount:LONG              /* number of promiscuous listeners */
  130.  
  131.  
  132. /*
  133.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  134.  * input routines have queues of messages stored on ifqueue structures
  135.  * (defined above).  Entries are added to and deleted from these structures
  136.  * by these macros, which should be called with ipl raised to splimp().
  137.  */
  138. #define IF_QFULL(ifq)           ((ifq).ifq_len >= (ifq).ifq_maxlen)
  139. #define IF_DROP(ifq)            ((ifq).ifq_drops++)
  140.  
  141. /* --- must convert ---
  142. #define IF_ENQUEUE(ifq, m) { \
  143.         (m)->m_nextpkt = 0; \
  144.         if ((ifq)->ifq_tail == 0) \
  145.                 (ifq)->ifq_head = m; \
  146.         else \
  147.                 (ifq)->ifq_tail->m_nextpkt = m; \
  148.         (ifq)->ifq_tail = m; \
  149.         (ifq)->ifq_len++; \
  150. }
  151. #define IF_PREPEND(ifq, m) { \
  152.         (m)->m_nextpkt = (ifq)->ifq_head; \
  153.         if ((ifq)->ifq_tail == 0) \
  154.                 (ifq)->ifq_tail = (m); \
  155.         (ifq)->ifq_head = (m); \
  156.         (ifq)->ifq_len++; \
  157. }
  158. #define IF_DEQUEUE(ifq, m) { \
  159.         (m) = (ifq)->ifq_head; \
  160.         if (m) { \
  161.                 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
  162.                         (ifq)->ifq_tail = 0; \
  163.                 (m)->m_nextpkt = 0; \
  164.                 (ifq)->ifq_len--; \
  165.         } \
  166. }
  167. */
  168.  
  169. #define IFQ_MAXLEN      50
  170. #define IFNET_SLOWHZ    1               /* granularity is 1 second */
  171.  
  172. #endif /* KERNEL */
  173.  
  174. #define IFF_UP          $1             /* interface is up */
  175. #define IFF_BROADCAST   $2             /* broadcast address valid */
  176. #define IFF_DEBUG       $4             /* turn on debugging */
  177. #define IFF_LOOPBACK    $8             /* is a loopback net */
  178. #define IFF_POINTOPOINT $10            /* interface is point-to-point link */
  179. #define IFF_NOTRAILERS  $20            /* avoid use of trailers */
  180. #define IFF_RUNNING     $40            /* resources allocated */
  181. #define IFF_NOARP       $80            /* no address resolution protocol */
  182. #define IFF_SIMPLEX     $800           /* can't hear own transmissions */
  183.  
  184. /* next two not supported now, but reserved: */
  185. #define IFF_PROMISC     $100           /* receive all packets */
  186. #define IFF_ALLMULTI    $200           /* receive all multicast packets */
  187. #define IFF_OACTIVE     $400           /* transmission in progress */
  188.  
  189. /* flags set internally only: */
  190. #define IFF_CANTCHANGE \
  191.         (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|IFF_SIMPLEX)
  192.  
  193. /*
  194.  * The ifaddr structure contains information about one address
  195.  * of an interface.  They are maintained by the different address families,
  196.  * are allocated and attached when an address is set, and are linked
  197.  * together so all addresses for an interface can be located.
  198.  */
  199. OBJECT ifaddr
  200.     ifa_addr:PTR TO sockaddr,     /* address of interface */
  201.     ifa_dstaddr:PTR TO sockaddr,  /* other end of p-to-p link */
  202.     ifa_netmask:PTR TO sockaddr,  /* used to determine subnet */
  203.     ifa_ifp:PTR TO ifnet,         /* back-pointer to interface */
  204.     ifa_next:PTR TO ifaddr,       /* next address for interface */
  205.     ifa_rtrequest:LONG,   /* check or clean routes (+ or -)'d */
  206.     ifa_rt:PTR TO rtentry,        /* ??? for ROUTETOIF */
  207.     ifa_flags:UWORD,              /* mostly rt_flags for cloning */
  208.     ifa_llinfolen:UWORD          /* extra to malloc for link info */
  209.  
  210.  
  211. #define IFA_ROUTE       RTF_UP          /* route installed */
  212.  
  213.  
  214. /*
  215.  * Interface request structure used for socket
  216.  * ioctl's.  All interface ioctl's must have parameter
  217.  * definitions which begin with ifr_name.  The
  218.  * remainder may be interface specific.
  219.  */
  220. #define IFNAMSIZ        16
  221.  
  222. OBJECT  ifreq
  223.     ifr_name[16]:BYTE,             /* if name, e.g. "en0" */
  224.     [CUNION
  225.         ifru_addr:sockaddr,
  226.         ifru_dstaddr:sockaddr,
  227.         ifru_broadaddr:sockaddr,
  228.         ifru_flags:WORD,
  229.         ifru_metric:LONG,
  230.         ifru_data:PTR TO BYTE
  231.     ENDUNION]:ifr_ifru
  232.  
  233. #define ifr_addr        ifr_ifru.ifru_addr      /* address */
  234. #define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
  235. #define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
  236. #define ifr_flags       ifr_ifru.ifru_flags     /* flags */
  237. #define ifr_metric      ifr_ifru.ifru_metric    /* metric */
  238. #define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
  239.  
  240. OBJECT ifaliasreq
  241.     ifra_name[16]:BYTE,            /* if name, e.g. "en0" */
  242.     ifra_addr:sockaddr,
  243.     ifra_broadaddr:sockaddr,
  244.     ifra_mask:sockaddr
  245.  
  246.  
  247. /*
  248.  * Structure used in SIOCGIFCONF request.
  249.  * Used to retrieve interface configuration
  250.  * for machine (useful for programs which
  251.  * must know all networks accessible).
  252.  */
  253. OBJECT ifconf
  254.     ifc_len:LONG,                /* size of associated buffer */
  255.     [CUNION
  256.         ifcu_buf:PTR TO BYTE,
  257.         ifcu_req:PTR TO ifreq
  258.     ENDUNION]:ifc_ifcu
  259.  
  260. #define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
  261. #define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
  262.  
  263.  
  264.  
  265.